package com.xci.sys.entity;

import cn.afterturn.easypoi.excel.annotation.Excel;
import cn.afterturn.easypoi.excel.annotation.ExcelIgnore;
import cn.hutool.core.date.DateUtil;
import com.xci.core.internal.Const;
import com.xci.core.domain.BaseOperateUserEntity;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.hibernate.validator.constraints.Length;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;

/**
 * 系统操作日志
 */
@Data
@EqualsAndHashCode(callSuper = true)
@ApiModel(description = "系统操作日志")
public class SysOperateLog extends BaseOperateUserEntity {
    /**
     * 日志主键
     */
    @ApiModelProperty(value = "日志主键", required = true, position = 1)
    private String id;

    /**
     * 日志模块
     */
    @Length(max = 100, message = "日志模块长度不能超过{max}")
    @ApiModelProperty(value = "日志模块", position = 2)
    private String module;

    /**
     * 操作信息
     */
    @ApiModelProperty(value = "操作信息", position = 3)
    private String msg;

    /**
     * 操作方法
     */
    @Length(max = 500, message = "操作方法长度不能超过{max}")
    @ApiModelProperty(value = "操作方法", position = 4)
    private String method;

    /**
     * 请求参数
     */
    @ApiModelProperty(value = "请求参数", position = 5)
    private String reqParam;

    /**
     * 请求地址
     */
    @Length(max = 500, message = "请求地址长度不能超过{max}")
    @ApiModelProperty(value = "请求地址", position = 6)
    private String reqUrl;

    /**
     * 请求方式
     */
    @Length(max = 20, message = "请求方式长度不能超过{max}")
    @ApiModelProperty(value = "请求方式", position = 7)
    private String reqType;

    /**
     * 耗时毫秒数
     */
    @ApiModelProperty(value = "耗时毫秒数", position = 8)
    private Long costTime;

    public String getCostTimeText() {
        if (costTime != null)
            return DateUtil.formatBetween(costTime);
        return Const.EMPTY;
    }

    /**
     * 浏览器
     */
    @Length(max = 100, message = "浏览器长度不能超过{max}")
    @ApiModelProperty(value = "浏览器", position = 11)
    private String browser;

    /**
     * 操作系统
     */
    @Length(max = 100, message = "操作系统长度不能超过{max}")
    @ApiModelProperty(value = "操作系统", position = 12)
    private String os;

    /**
     * 操作状态 [成功_1,失败_0]
     */
    @NotNull(message = "请输入操作状态")
    @Excel(name = "操作状态", width = 20d, replace = { "成功_1", "失败_0" })
    @ApiModelProperty(value = "操作状态 [成功_1,失败_0]", required = true, position = 14)
    private Boolean status;

    /**
     * 应用主键
     */
    @Length(max = 100, message = "应用主键长度不能超过{max}")
    @ApiModelProperty(value = "应用主键", position = 15)
    private String appId;

    /**
     * 应用名称
     */
    @Length(max = 100, message = "应用名称长度不能超过{max}")
    @ApiModelProperty(value = "应用名称", position = 16)
    private String appName;

    /**
     * 操作人机构主键
     */
    @Length(max = 100, message = "操作人机构主键长度不能超过{max}")
    @ApiModelProperty(value = "操作人机构主键", position = 19)
    private String operateDeptId;

    /**
     * 操作人机构名称
     */
    @Length(max = 100, message = "操作人机构名称长度不能超过{max}")
    @ApiModelProperty(value = "操作人机构名称", position = 20)
    private String operateDeptName;
}